//
//  ALMacro.h
//  ios-loan
//
//  Created by mac on 2018/3/28.
//  Copyright © 2018年 hxhg. All rights reserved.
//

#ifndef ALMacro_h
#define ALMacro_h

#import "MacroDefinition.h"

#pragma mark -
#pragma mark 申明为单例
#undef    AL_AS_SINGLETON
#define AL_AS_SINGLETON( __class ) \
+ (__class *)sharedInstance;\

#undef    AL_DEF_SINGLETON
#define AL_DEF_SINGLETON( __class ) \
+ (__class *)sharedInstance \
{ \
static dispatch_once_t once; \
static __class * __singleton__; \
dispatch_once( &once, ^{ __singleton__ = [[__class alloc] init]; } ); \
return __singleton__; \
}

#define kDateFormat @"yyyy-MM-dd HH:mm:ss"
#define kDateFormat2 @"yyyy-MM-dd HH"
#define D_MBS_DATE_Fortmat @"yyyyMMdd"
#define D_MBS_TIME_Format @"HHmmss"

#pragma mark - color
#define RGB(r, g, b)             [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0]
#define RGBAlpha(r, g, b, a)     [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)]

#define HexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define HexRGBAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]

#pragma mark 屏幕相关
#pragma mark -
#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
#define kStatusBarHeight 20.0f
#define kNavigationBarHeight 44.0f
#define kStarusBarBotom (isAfterIOS7 ? 20:0)
#define kNavigationBarBotom (isAfterIOS7 ? (20+44):(0+44))
#define kNavigationBarLandscapeHeight 33.0f
#define kTabBarHeight 49.0f
#define kToolBarHeight 44.0f
#define kContentViewHeight (kScreenHeight - kNavigationBarBotom - kTabBarHeight)

#define kLeftSep 10.0f
#define kRightSep 10.0f
#define kPickerViewHeight 216.0f

#pragma mark Device
#pragma mark -
#define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4)
#define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5)
#define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6)
#define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7)
#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8)

#define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>=4)
#define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>=5)
#define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>=6)
#define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>=7)
#define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>=8)

#define isRetina ([[UIScreen mainScreen] scale]==2)
#define isIphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

#define isAfterIphone6 ([UIScreen mainScreen].bounds.size.width>=750/2)


#define TSelectViewWillShowNotification @"TSelectViewWillShowNotification"
#define TSelectViewWillHideNotification @"TSelectViewWillHideNotification"
#define kAppTimeoutInterval     @"AppTimeoutInterval"
#define MBUserDidLogoutNotification @"MBUserDidLogoutNotification"

#define TSelectViewWillShowNotification @"TSelectViewWillShowNotification"
#define TSelectViewWillHideNotification @"TSelectViewWillHideNotification"
#define MBSelectViewDidShowNotification @"MBSelectViewDidShowNotification"
#define MBSelectViewDidHideNotification @"MBSelectViewDidHideNotification"
#define MBAlertViewDidHideNotification @"MBAlertViewDidHideNotification"



//----------------------系统----------------------------
//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

#define kDevice_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

//获取系统版本
#define kIOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define kCurrentSystemVersion [[UIDevice currentDevice] systemVersion]

//检查系统版本
#define kSYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define kSYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define kSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define kSYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define kSYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)





//----------------------内存----------------------------

//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif

#pragma mark - common functions
#define kRELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }

//释放一个对象
#define kSAFE_DELETE(P) if(P) { [P release], P = nil; }

#define kSAFE_RELEASE(x) [x release];x=nil

#define WeakSelf __weak __typeof (self) weakself = self;
#define StrongSelf  __strong __typeof (weakself) strongSelf = weakself;



//----------------------图片----------------------------
/// 读取本地图片
#define kImageFromBundleNameType(fileName,fileType) ([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:fileType]])

/// 定义UIImage对象
#define kImageFromBundleName(name) ([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:name ofType:nil]])

/// 获取图片，根据图片名称
#define kImageWithName(name) [UIImage imageNamed:name]

/// 获取图片，根据图片url
#define kImageWithURL(name) [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:URLWithString(name)]]

/// 拉伸图片边框处理
#define kImageUIEdgeWithName(name) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5) resizingMode:UIImageResizingModeStretch]

/// 拉伸图片边框处理
#define kImageWithUIEdge(name, UIEdgeInsets) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsets resizingMode:UIImageResizingModeStretch]





//----------------------颜色类---------------------------
// rgb颜色转换（16进制->10进制）
#define kRGBFromHexadecimal(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define kRGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define kRGB(r,g,b) RGBA(r,g,b,1.0f)


//----------------------字体---------------------------
#define kFontName_PingFangSC_Regular (isAfterIOS9)?@"PingFangSC-Regular":@"HiraMinProN-W6"
#define kFontName_PingFangSC_Medium  (isAfterIOS9)?@"PingFangSC-Medium":@"HiraKakuProN-W6"
#define kFontName_PingFangSC_Semibold  (isAfterIOS9)?@"PingFangSC-Semibold":@"HiraKakuProN-W6"

//----------------------字符串---------------------------
#define string_obj(arg) [NSString stringWithFormat:@"%@",arg]
#define string_int(arg) [NSString stringWithFormat:@"%d",arg]
#define string_longlong(arg) [NSString stringWithFormat:@"%lld",arg]
#if defined(__LP64__) && __LP64__
#define string_integer(arg) [NSString stringWithFormat:@"%ld",arg]
#else
#define string_integer(arg) [NSString stringWithFormat:@"%d",arg]
#endif
#define string_float(arg) [NSString stringWithFormat:@"%f",arg]
#define string_double(arg) [NSString stringWithFormat:@"%f",arg]
#define string_bool(arg) [NSString stringWithFormat:@"%d",arg]


//----------------------其他----------------------------

//G－C－D
#define kRunInGlobalQueue(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define kRunInMainQueue(block) dispatch_async(dispatch_get_main_queue(),block)

//NSUserDefaults 实例化
#define kUSER_DEFAULT [NSUserDefaults standardUserDefaults]

#define kCacheDir [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
#define kDocumentDir [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
#define kTempDir NSTemporaryDirectory()
#define kHomeDir NSHomeDirectory()

#endif /* ALMacro_h */
